﻿/**
 * 显示新闻公告的网页，
 * 支持URL方式直接打开 http://localhost:8080/jxstar2/page.jsp?nodeid=oa_news_read&usercode=admin&news_id=jxstar-531-1101
 */
Jxstar.currentPage = function() {
	var page = new Ext.Container({html: '', autoScroll:true});
	var getUrlParam = function(name) {
		var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if(r!=null)return  unescape(r[2]); return null;
	};
	
	//显示消息内容对话框
	var showWin = function(data) {
		var userid = JxDefault.getUserId();
		var edit_userid = data.cont.edit_userid;

		//创建消息显示内容
		var html = JxSender.contHtml(data.cont);
		var replys = data.reply;
		//添加评论输入栏
		
		//添加评论标题
		if (replys.length > 0) {
			html += '<div class="x-reply-body"><div class="title">'+jx.cloud.text19+'</div>';//全部评论
		}
		for (var i = 0, n = replys.length; i < n; i++) {
			html += JxSender.replyHtml(i+1, replys[i], edit_userid);
		}
		if (replys.length > 0) {
			html += '</div>';
		}
		
		//创建先生消息内容的panel
		page.update(html);
		
		//延时加载，避免 page.el 没有创建
		JxUtil.delay(1000, function(){
			//添加回复编辑控件
			new Ext.form.TextArea({
				renderTo: page.el.query('.x-news-reply .content')[0], 
				id:'oa_reply__reply_cont', maxLength:500, height:100, width:'100%'
			});
			new Ext.Button({
				renderTo: page.el.query('.x-news-reply .button')[0],
				cls:'x-btn-primary', iconCls:'eb_reply',
                text:jx.plet.text5, handler:function(){JxSender.saveReply(news_id, page.ownerCt);}
			});
			
			//添加删除事件
			JxSender.addDelete(page);
		});
	};
	
	//返回的数据格式为：{cont:{...}, reply:[...]}，第一部分为消息，第二部分为回复
	var hdcall = function(data) {
		if (Ext.isEmpty(data)) {
			JxHint.alert(jx.plet.notboard);
		} else {
			showWin(data);
		}
	};    
    var news_id = getUrlParam('news_id');
	var params = 'funid=oa_reply&eventcode=fqury&pagetype=form&isReply=0&newsId='+news_id;
	Request.dataRequest(params, hdcall);
    
	return page;
}